package testGameObjects;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import YAPserver.gameObjects.Line;
import YAPserver.gameObjects.Point;

public class TestPoint {
	Line line1;
	Point point1;
	Point point2;
	Point point3;
	@Before
	public void setup() throws Exception{
		line1 = new Line(new Point(0,0), new Point(8,8));
		point1 = new Point(7, 8);
		point2 = new Point(3, 3);
		point3 = new Point(-1, -1);
	}
	
	@Test
	public void testAddition(){
		Point result = point1.add(point2);
		assertTrue(result.equals(new Point(10,11)));
	}
	@Test
	public void testSubtraction(){
		Point result = point1.subtract(point2);
		assertTrue(result.equals(new Point(4,5)));
		
		result = point2.subtract(point1);
		assertTrue(result.equals(new Point(-4,-5)));	
	}
	@Test
	public void testIsElementOneD(){
		boolean result1 = point1.isElementOneD(line1);
		boolean result2 = point2.isElementOneD(line1);
		boolean result3 = point3.isElementOneD(line1);
		boolean result4 = line1.getEndPoint().isElementOneD(line1);
		assertTrue(result1);
		assertTrue(result2);
		assertFalse(result3);
		assertTrue(result4);
	}
	@Test
	public void testIsElementOneDAgain(){
		Point point = new Point(0, 2);
		Line line = new Line(new Point(0, 0), new Point(0, 10));
		boolean result = point.isElementOneD(line);
		assertTrue(result);
	}
	@Test
	public void testIsElementTwoD(){
		boolean result1 = point1.isElementTwoD(line1);
		boolean result2 = point2.isElementTwoD(line1);
		assertFalse(result1);
		assertTrue(result2);
	}
}
